package com.vlong.town.controller.client.hotel;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.vlong.town.controller.base.BaseController;
import com.vlong.town.entity.hotel.HotelInfo;
import com.vlong.town.service.hotel.HotelInfoService;
import com.vlong.town.util.data.DataUtil;
import com.vlong.town.util.pagination.PageTag;

/**
 * 休闲农庄控制器
 * @author 51088
 *
 */
@Controller
@RequestMapping("/client/hotel")
public class HotelClientController extends BaseController{
	
	@Autowired
	private HotelInfoService hotelInfoService;//休闲农庄业务接口
	
	/**
	 * 跳转休闲农庄页面
	 * @param pageNo
	 * @param pageSize
	 * @return
	 */
    @RequestMapping("/list")
    public String gotoHotelInfoPage(
            @RequestParam(required=false, value="pageNo") Integer pageNo,
            @RequestParam(required=false, value="pageSize") Integer pageSize
    		) {
        PageHelper.startPage(getPageNo(pageNo), getPageSize(pageSize));
        PageHelper.orderBy("create_time DESC");
        List<HotelInfo> hotelInfoList = this.hotelInfoService.queryList(null, null,null, null,2);
        PageInfo<HotelInfo> pageInfo = new PageInfo<HotelInfo>(hotelInfoList);
        PageTag<HotelInfo> pt = new PageTag<HotelInfo>(request, "list", pageInfo);
        request.setAttribute("pageHtml", pt.getPageHtml());
        for(HotelInfo hotelInfo : hotelInfoList) {
        	hotelInfo.setThumbnail(request.getScheme()+"://"+request.getServerName()+":"+ request.getServerPort() + request.getContextPath() + "/cdkeditor/" + hotelInfo.getThumbnail());
            hotelInfo.setContent(DataUtil.delHTMLTag(hotelInfo.getContent(), 0));
            Long createTime = hotelInfo.getCreateTime();
        	SimpleDateFormat  sdf=new  SimpleDateFormat("yyyy-MM-dd");
        	Date date = new  Date(createTime);
        	String format = sdf.format(date);
        	String createDate="["+format+"]";
        	hotelInfo.setCreateDate(createDate);
        }
        request.setAttribute("hotelInfoList", hotelInfoList);
        //获取SESSION信息
  		String telphone = getTelphone();
  		request.setAttribute("telphone", telphone);
        return "client/hotel/list_hotel";
    }
	
	
    /**
	 * 进去详情页面
	 * @param goodsId
	 * @return
	 */
	@RequestMapping("/detail/{hotelId}")
	public String detail(@PathVariable(required=false, value="hotelId") String hotelId){
		HotelInfo hotel = hotelInfoService.queryById(Long.parseLong(hotelId));
		request.setAttribute("hotel", hotel);
		 //获取SESSION信息
  		String telphone = getTelphone();
  		request.setAttribute("telphone", telphone);
		return "client/hotel/detail_hotel";
	}
	
	

}
